﻿#ifndef LIMATHREAD_H
#define LIMATHREAD_H

#include <QThread>
#include "export.hpp"
class MainDemoWindow;
#define USEREVENT_USER_SENDMESSAGE      0x01
#define USEREVENT_USER_SETENGINETYPE    0x02
class limaThread: public QThread{
    Q_OBJECT
public:
    limaThread(MainDemoWindow*  _owner);
    void SetUpEngine();
    void closeThread();
    std::string GetRoomId();
    std::string GetUserId();
    void SendMsg(const QString & msg,const QString & peerId);
public slots:
    void Slot_SetVideoParam();
    void Slot_switchEnginType(const QString & typedesc);
    void Slot_connPeer();
protected:
    virtual void run();
    static void OnGotAudioFrame(const char* audioData,
                                    uint32_t frequency,
                                    uint32_t nBytesPerSample,
                                    uint32_t number_of_channels,
                                    uint32_t number_of_samplesperchanel);
    static void OnGotVideoFrame(uint32_t w,uint32_t h,const char *y, uint32_t y_size,
                                 const char *u, uint32_t u_size,
                                 const char *v, uint32_t v_size,
                                 uint64_t timestamp);
    void InitFakeAudioCapturer() ;
signals:
    void    Sig_NewUser(const QString  uid);
    void    Sig_UserLeaved(const QString  uid);
private:
    static LimaEngineType checkTypeFromDescStr(const QString  typedesc);
private:
    volatile bool                   _isStop;       //isStop是易失性变量，需要用volatile进行申明
    static void *                   _engine;
    static std::mutex               _engineMutex;
    static MainDemoWindow*          _ownerWindow;
    static bool                     _isVideoSetting;
    static bool                     _isAudioSetting;
    static LimaEngineType           _defaulttype;
};
#endif // LIMATHREAD_H
